package com.minsf.springbootinit.model.enums;

import io.swagger.models.auth.In;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.apache.commons.lang3.ObjectUtils;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @Description
 * @Author minify
 * @Date 2024/1/3 21:47
 * @Project oj-backend
 */
@Getter
@AllArgsConstructor
public enum QuestionSubmitStatusEnum {

    //0-待判题、1-判题中、2-成功，3-失败
    UNDETERMINED_QUESTION("待判题", 0),
    JUDGMENT_OF_QUESTION("判题中", 1),
    JUDGMENT_SUCCESS("成功", 2),
    JUDGMENT_FAILED("失败", 3);

    private final String name;
    private final Integer value;

    /**
     * 获取值列表
     *
     * @return
     */
    public static List<Integer> getValues() {
        return Arrays.stream(values()).map(item -> item.value).collect(Collectors.toList());
    }

    /**
     * 根据 value 获取枚举
     *
     * @param value
     * @return
     */
    public static QuestionSubmitStatusEnum getEnumByValue(Integer value) {
        if (ObjectUtils.isEmpty(value)) {
            return null;
        }
        for (QuestionSubmitStatusEnum anEnum : QuestionSubmitStatusEnum.values()) {
            if (anEnum.getValue().equals(value)) {
                return anEnum;
            }
        }
        return null;
    }
}